package technical_engineering.procedures;

import technical_engineering.TechnicalEngineeringMod;

import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;

import java.util.Map;

public class SpannerModeProcedure {
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			if (!dependencies.containsKey("entity"))
				TechnicalEngineeringMod.LOGGER.warn("Failed to load dependency entity for procedure SpannerMode!");
			return;
		}
		if (dependencies.get("itemstack") == null) {
			if (!dependencies.containsKey("itemstack"))
				TechnicalEngineeringMod.LOGGER.warn("Failed to load dependency itemstack for procedure SpannerMode!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		ItemStack itemstack = (ItemStack) dependencies.get("itemstack");
		if ((!(entity.isSneaking()))) {
			if ((((itemstack).getOrCreateTag().getDouble("mode")) == 0)) {
				(itemstack).getOrCreateTag().putDouble("mode", 1);
				if (entity instanceof PlayerEntity && !entity.world.isRemote()) {
					((PlayerEntity) entity)
							.sendStatusMessage(new StringTextComponent((new TranslationTextComponent("message.spanner.mode.1").getString())), (true));
				}
			} else if ((((itemstack).getOrCreateTag().getDouble("mode")) == 1)) {
				(itemstack).getOrCreateTag().putDouble("mode", 2);
				if (entity instanceof PlayerEntity && !entity.world.isRemote()) {
					((PlayerEntity) entity)
							.sendStatusMessage(new StringTextComponent((new TranslationTextComponent("message.spanner.mode.2").getString())), (true));
				}
			} else if ((((itemstack).getOrCreateTag().getDouble("mode")) == 2)) {
				(itemstack).getOrCreateTag().putDouble("mode", 0);
				if (entity instanceof PlayerEntity && !entity.world.isRemote()) {
					((PlayerEntity) entity)
							.sendStatusMessage(new StringTextComponent((new TranslationTextComponent("message.spanner.mode.0").getString())), (true));
				}
			}
		}
	}
}
